package com.lanou3g.musicenjoy.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lanou3g.musicenjoy.activities.HelloDrawerActivity;
import com.lanou3g.musicenjoy.entity.Recommendation;
import com.lanou3g.musicenjoy.fragment.NewLeftFragment;
import com.lanou3g.musicenjoy.activities.RingActivity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 15/10/23.
 */
public class ViewPagerAdapter extends PagerAdapter{
    private List<Recommendation.PicEntity> datas;
    private Context mContext;
    private HelloDrawerActivity activity;
    private NewLeftFragment leftFragment;

    public   ViewPagerAdapter(Context c,List<Recommendation.PicEntity> data){
        mContext=c;
        activity = (HelloDrawerActivity) c;
        datas=data;
        leftFragment=new NewLeftFragment();

    }
    @Override
    public int getCount() {
        return datas!=null&&datas.size()>0?Integer.MAX_VALUE:0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        ImageView imageView=new ImageView(mContext);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("ajajajaja",datas.get(position%datas.size()).getType()+"");
                if (datas.get(position%datas.size()).getType()==7){
                    activity.skepFrament(position, datas);

                }else {
                    Log.i("ajajajaaj","你点击了");

                    Log.i("ajajjaja",datas.get(position%datas.size()).getCode());
                    Intent intent=new Intent(mContext, RingActivity.class);
                    intent.putExtra("weburl",datas.get(position%datas.size()).getCode());
                    mContext.startActivity(intent);
                }

            }
        });
        Recommendation.PicEntity entity=datas.get(position%datas.size());
        Picasso.with(mContext).load(entity.getRandpic()).into(imageView);
        //图片填充布局
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        container.addView(imageView);

        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
    }
}
